<?php

	session_start();
	$username = $_SESSION['username'];
	$id = $_SESSION['id'];

?>

<head>
	<link rel="stylesheet" type="text/css" href="profile_inner.css" />

	<script type="text/javascript" src="javascript/calendarDateInput.js">

  	/***********************************************
  	* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
  	* Script featured on and available at http://www.dynamicdrive.com
  	* Keep this notice intact for use.
  	***********************************************/

  	</script>
</head>

<?php

	//edit the user's profile
	
	require_once "../common/PinSQL.obj";
	$pinSQL = new pinSQL();
	
	$pinSQL->Query("SELECT * FROM members WHERE id='$id'");
	$row = $pinSQL->FetchNextRow();
	$firstname = $row['firstname'];
	$lastname = $row['lastname'];
	$email = $row['email'];
	
	$pinSQL->Query("SELECT * FROM memberdata WHERE id='$id'");
	$row = $pinSQL->FetchNextRow();

//upload an image
?>

<img src="/img/icons/back.gif"><a href="frame.php?page=profile"> Return to profile </a>

<div class="padded_text">
	<div class="head">Edit Profile</div>

	<p /><div class="subhead">User photo</div>
	
	<table>
	<tr>
	<td>
<?php
	$picurl = $row['picurl'];
	
	if ($picurl)
	{
		$imageSize = getimagesize("userData/$username/$picurl");
		
		if ($imageSize[0] <= 200)
		{
			$newWidth = $imageSize[0];
			$newHeight = $imageSize[1];
		} else {
			$heightFactor = $imageSize[1] / $imageSize[0];
			$newWidth = 200;
			$newHeight = $newWidth * $heightFactor;
		}
		
?>
		<img src="userData/<?php echo $username . "/" . $picurl; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" />	
<?php

	}
	else
	{
		
?>
		<img src="/img/icons/nopic.png" />
<?php
	}
?>
	</td>
	
	<td>
	<form name="pic" method="post" enctype="multipart/form-data" action="upload.php?type=pictures">
		<div class="subhead">Location of image on this computer:</div>
		<div class="small">File types: .jpg, .gif, or .png</div>
		<br><input type="hidden" name="username" value="<?php echo $username; ?>" />
		<input class="inputField" type="file" id="file" name="file" />
		<input name="name" type="hidden" value="__userpic__"/>
		<br><input class="inputFieldR" type="submit" value="Upload Photo" onclick="StartUpload();" />
	</form>
	
	<div id="pleasewait_div" style="display: none;"><img src="/img/uploading.gif" /> Uploading user picture...</div>
	
	<div class="uploaderror" id="uploaderror"></div>
	</td>
	</tr>
	</table>

	<a name="personal_info"></a>
	<p /><div class="subhead">Personal Info</div>
	Please enter your personal information into the fields below.

<?php
	
	$sex = $row['sex'];
	$city = $row['city'];
	$state = $row['state'];
	$country = $row['country'];
	$website = $row['website'];
	$screenname = $row['screenname'];
	$phone = $row['phone'];
	$carrier = $row['carrier'];
	$cellnotify = $row['cellnotify'];
	$email_notify = $row['email_notify'];
	$birthday = $row['birthday'];
	
	if (!$birthday)
		$birthday = '1969-7-24';

?>
	<form>
	<p /><table>
		<tr>
			<td style="vertical-align: top;">First Name: <br>Last Name:</td>
			<td><input type="text" id="firstname" class="inputField" value="<?php echo $firstname; ?>" />
			<br><input type="text" id="lastname" class="inputField" value="<?php echo $lastname; ?>" /></td>
		</tr>
		
		<tr>
			<td>Birthday:</td>
			<td><script>DateInput('birthday', true, 'YYYY-MM-DD', '<?php echo $birthday; ?>')</script></td>		
		</tr>		
		
		<tr>
			<td>E-mail address:</td>
			<td><input type="text" id="email" class="inputField" value="<?php echo $email; ?>" /></td>
		</tr>
		
		<tr>
			<td>Sex:</td>
			<td><input type="radio" id="sex_m" name="sex" class="inputField" value="m" <?php if ($sex=="m") echo "checked" ?>/><img src="/img/icons/male.gif" />
			<br /><input type="radio" id="sex_f" name="sex" class="inputField" value="f" <?php if ($sex=="f") echo 'checked' ?>/><img src="/img/icons/female.gif" /></td>
		</tr>
		
		<tr>
			<td>City:</td>
			<td><input type="text" id="city" class="inputField" value="<?php echo $city; ?>" /></td>
		</tr>
		
		<tr>
			<td>State:</td>
			<td><input type="text" id="state" class="inputField" value="<?php echo $state; ?>" /></td>
		</tr>
		
		<tr>
			<td>Country:</td>
			<td><input type="text" id="country" class="inputField" value="<?php echo $country; ?>" /></td>
		</tr>
		
		<tr>
			<td>Website:</td>
			<td><input type="text" id="website" class="inputField" value="<?php echo $website; ?>" /></td>
		</tr>
		
		<tr>
			<td>Screen Name:</td>
			<td><input type="text" id="screenname" class="inputField" value="<?php echo $screenname; ?>" /></td>
		</tr>
		
		<tr>
			<td>Phone Number:<br /><span class="small">(10-digit, no spaces)<br />ex. 2125554965</span></td>
			<td style="vertical-align: top;"><input type="text" id="phone" class="inputField" value="<?php echo $phone; ?>" /></td>
		</tr>
		
		<tr>
			<td>Carrier:</td>
			<td><select class="inputField" id="carrier">
				<option <?php if ($carrier=="att") echo "selected" ?> >AT&T</option>
				<option <?php if ($carrier=="Verizon") echo "selected" ?> >Verizon</option>
				<option <?php if ($carrier=="T-Mobile") echo "selected" ?> >T-Mobile</option>
				<option <?php if ($carrier=="Sprint") echo "selected" ?> >Sprint</option>
				<option <?php if ($carrier=="Nextel") echo "selected" ?> >Nextel</option>
			</select></td>
		</tr>
		
		<tr>
			<td>Cellular notification:</td>
			<td><input type="radio" id="cellnotify_on" name="cellnotify" class="inputField" value="on" <?php if ($cellnotify=="1") echo "checked" ?>/>On
			<br /><input type="radio" id="cellnotify_off" name="cellnotify" class="inputField" value="off" <?php if ($cellnotify=="0") echo 'checked' ?>/>Off</td>
		</tr>
		
		<tr>
			<td>E-mail notification:</td>
			<td><input type="radio" id="email_notify_on" name="email_notify" class="inputField" value="on" <?php if ($email_notify=="1") echo "checked" ?>/>On
			<br /><input type="radio" id="email_notify_off" name="email_notify" class="inputField" value="off" <?php if ($email_notify=="0") echo 'checked' ?>/>Off</td>
		</tr>
		
		<tr>
			<td><span id="confirmation1" class="redtext" style="display: none;"><img src="/img/ajax_sm.gif" /> Updating...</span></td>
			<td><input type="button" value="Update" class="inputFieldR" onclick="updatePersonalInformation();" /></td>
		</tr>
		
		<tr>
			<td></td>
			<td></td>
		</tr>
		
		<input type="hidden" value="<?php echo $id; ?>" id="id" />
		
	</table>
	</form>
	
	
	
</div>

<a name="artist_info"></a>
<p /><div class="subhead">Artist Info</div>
	
<?php
	$medium = $row['medium'];
	$influences = $row['influences'];
	$hobbies = $row['hobbies'];
	$interests = $row['interests'];
	$general = $row['general'];
	
?>
	<form>
	<p /><table>
		<tr>
			<td style="vertical-align: top;">Preferred Medium: </td>
			<td><input class="inputField" id="medium" type="text" value="<?php echo $medium; ?>"/></td>
		</tr>
		
		<tr>
			<td style="vertical-align: top;">Influences: </td>
			<td><textarea class="inputField" id="influences" rows=5 cols=31 ><?php echo $influences; ?></textarea></td>
		</tr>
		
		<tr>
			<td style="vertical-align: top;">Hobbies: </td>
			<td><textarea class="inputField" id="hobbies" rows=5 cols=31><?php echo $hobbies; ?></textarea></td>
		</tr>
		
		<tr>
			<td style="vertical-align: top;">Interests: </td>
			<td><textarea class="inputField" id="interests" rows=5 cols=31><?php echo $interests; ?></textarea></td>
		</tr>
		
		<tr>
			<td style="vertical-align: top;">General Information: </td>
			<td><textarea class="inputField" id="general" rows=5 cols=31><?php echo $general; ?></textarea></td>
		</tr>
		
		<tr>
			<td><span id="confirmation2" class="redtext" style="display: none;"><img src="/img/ajax_sm.gif" /> Updating...</span></td>
			<td><input type="button" value="Update" class="inputFieldR" onclick="updateArtistInformation();" /></td>
		</tr>
		
		<tr>
			<td></td>
			<td></td>
		</tr>
		
	
		
	</table>
	</form>
	
	
	
</div>

<script type="text/javascript">

	function updatePersonalInformation()
	{
		var firstname = document.getElementById('firstname').value;
		var lastname = document.getElementById('lastname').value;
		var email = document.getElementById('email').value;
		
		var sex;
		var city = document.getElementById('city').value;
		var state = document.getElementById('state').value;		
		var country = document.getElementById('country').value;		
		var website = document.getElementById('website').value;	
		var screenname = document.getElementById('screenname').value;	
		var phone = document.getElementById('phone').value;
		var birthday = document.getElementsByName('birthday')[0].value;
		var id = document.getElementById('id').value;
		
		var carrier = document.getElementById('carrier').value;
		if (carrier=="AT&T") carrier="att";
		
		var cellnotify = document.getElementById('cellnotify_on').checked * 1;
		var email_notify = document.getElementById('email_notify_on').checked * 1;
		
		var isMale = document.getElementById('sex_m').checked;
		if (isMale)
			sex = "m";
		else
			sex = "f";
		
		document.getElementById('confirmation1').style.display = 'block';
		document.getElementById('confirmation1').innerHTML = '<img src="/img/ajax_sm.gif" /> Updating...';
		
		// create the XMLHttpRequest object
		var request;
		try { request = new XMLHttpRequest(); }
		catch(e)
		{
			try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
		   	catch(e)
		   	{
		      	try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
		        	catch(e)
		        	{
		          	alert("Your browser will not support this webpage.");
		             	return false;
		        	}
		   	}
		}
		
		request.open("POST", 'updateinformation.php', true);
		
		request.onreadystatechange = function()
		{
			if (request.readyState == 4)
			{
				
		      	document.getElementById('confirmation1').innerHTML = "Updated!";
		      	
		   	}
		}

		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send('type=personal&firstname=' + firstname + '&lastname=' + lastname + '&birthday=' + birthday + '&email=' + email + 
			'&sex=' + sex + '&city=' + city + '&state=' + state +
			'&country=' + country + '&website=' + website + '&screenname=' + screenname +
			'&phone=' + phone + '&carrier=' + carrier + '&cellnotify=' + cellnotify + '&email_notify=' + email_notify + '&id=' + id); 
	}
	
	function updateArtistInformation()
	{
		var medium = document.getElementById('medium').value;
		var influences = document.getElementById('influences').value;
		var hobbies = document.getElementById('hobbies').value;
		var interests = document.getElementById('interests').value;
		var general = document.getElementById('general').value;
		var id = document.getElementById('id').value;
		
		document.getElementById('confirmation2').style.display = 'block';
		document.getElementById('confirmation2').innerHTML = '<img src="/img/ajax_sm.gif" /> Updating...';
		
		// create the XMLHttpRequest object
		var request;
		try { request = new XMLHttpRequest(); }
		catch(e)
		{
			try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
		   	catch(e)
		   	{
		      	try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
		        	catch(e)
		        	{
		          	alert("Your browser will not support this webpage.");
		             	return false;
		        	}
		   	}
		}
		
		request.open("POST", 'updateinformation.php', true);
		
		request.onreadystatechange = function()
		{
			if (request.readyState == 4)
			{
				
		      	document.getElementById('confirmation2').innerHTML = "Updated!";
		      	
		   	}
		}

		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		request.send('type=artist&medium=' + medium + '&influences=' + influences + '&hobbies=' + hobbies + 
							'&interests=' + interests + '&general=' + general + '&id=' + id); 
	}

	function StartUpload()
	{
		document.getElementById('pleasewait_div').style.display = 'block';
	}
		
</script>


